package com.woniu.controller;


import com.woniu.entity.HouseInfo;
import com.woniu.service.HouseInfoService;
import com.woniu.uitls.ResponseUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDate;

@RestController
@RequestMapping("/info")
//@CrossOrigin
public class PageInfoController {
    @Resource
    private HouseInfoService houseInfoService;

    @GetMapping("/{pageNum}/{pageSize}/{typeId}")
    public ResponseUtil findAll(@PathVariable Integer pageNum, @PathVariable Integer pageSize, @PathVariable Long typeId){

        ResponseUtil all = houseInfoService.findAll(pageNum, pageSize, typeId);
        System.out.println(all);
        return houseInfoService.findAll(pageNum,pageSize,typeId);
    }
    @GetMapping("/findById/{houseId}")
    public ResponseUtil findById(@PathVariable Long houseId){
        return houseInfoService.findById(houseId);

    }
    @PostMapping()
    public Integer add(HouseInfo houseInfo){
        houseInfo.setPublishDate(LocalDate.now());
        return houseInfoService.add(houseInfo);

    }
    @PutMapping()
public Integer update(@RequestBody  HouseInfo houseInfo){
        return houseInfoService.update(houseInfo);
    }
    @DeleteMapping("/{houseId}")
    public Integer delete(@PathVariable Integer houseId){
        return houseInfoService.delete(houseId);
    }
}
